Add option to write Lowrance version 3 of .usr format.
authorrobertl <robertl>
Sat, 16 Aug 2008 02:19:35 +0000 (02:19 +0000)
committerrobertl <robertl>
Sat, 16 Aug 2008 02:19:35 +0000 (02:19 +0000)
lowranceusr.c
reference/lowrance-v2-unicsv.txt [new file with mode: 0644]
reference/lowrance-v2.usr [new file with mode: 0644]
reference/lowrance-v3-unicsv.txt [new file with mode: 0644]
reference/lowrance-v3.usr [new file with mode: 0644]

index 93edd8ce583ed7479105f298bfd7ec9e367f4562..4620e8cf75519906c02ba4cc0611b039dc2f5105 100644 (file)
@@ -207,7 +207,9 @@ static char *ignoreicons;
 static char *writeasicons;
 static char *merge;
 static char *seg_break;
+static char *wversion_arg;
 static int reading_version;
+static int writing_version;
 
 #define MYNAME "Lowrance USR"
 
@@ -290,6 +292,8 @@ arglist_t lowranceusr_args[] = {
        NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
        {"break", &seg_break, "(USR input) Break segments into separate tracks",
        NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
+       {"wversion", &wversion_arg, "(USR output) Write version",
+       "2", ARGTYPE_INT, "2", "3" },
        ARG_TERMINATOR
 };
 
@@ -311,6 +315,7 @@ wr_init(const char *fname)
        file_out = gbfopen_le(fname, "wb", MYNAME);
        mkshort_handle = mkshort_new_handle();
        waypt_out_count = 0;
+        writing_version = atoi(wversion_arg);
 }
 
 static void
@@ -336,12 +341,12 @@ lon_deg_to_mm(double x) {
 
 static double 
 lat_mm_to_deg(double x) {
-       return (2 * atan(exp(x / SEMIMINOR)) - M_PI / 2) / DEGREESTORADIANS;
+       return (2.0 * atan(exp(x / SEMIMINOR)) - M_PI / 2.0) / DEGREESTORADIANS;
 }
 
 static long
 lat_deg_to_mm(double x) {
-       return (long)(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2) / 2)));
+       return (long)(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2.0) / 2.0)));
 }
 
 static void
@@ -358,6 +363,7 @@ lowranceusr_parse_waypt(waypoint *wpt_tmp)
        if (wpt_tmp->altitude <= UNKNOWN_USR_ALTITUDE) {
                wpt_tmp->altitude = unknown_alt;
        }
+
        text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
        if (text_len) {
                buff[text_len] = '\0';
@@ -400,11 +406,13 @@ lowranceusr_parse_waypt(waypoint *wpt_tmp)
        if (global_opts.debug_level >= 1)
                printf(MYNAME " parse_waypt: waypt_type = %d\n",waypt_type);
 
-    // Version 3 has an extra word in here that we don't know about.
-    if (reading_version >= 3) {
-      int junkword = gbfgetint32(file_in);
-      (void)junkword;
-    }
+        // Version 3 has a depth field here.
+        if (reading_version >= 3) {
+          float depth_feet = gbfgetflt(file_in);
+          if (abs(depth_feet - 99999.0)  > .1)
+            WAYPT_SET(wpt_tmp, depth, FEET_TO_METERS(depth_feet));
+        }
+
 }
 
 
@@ -650,6 +658,12 @@ lowranceusr_waypt_disp(const waypoint *wpt)
        gbfputint32(Lon, file_out);
        gbfputint32(alt, file_out);
 
+        if (writing_version >= 3) {
+          float depth = WAYPT_HAS(wpt, depth) ?
+              METERS_TO_FEET(wpt->depth) : -99999.0;
+          gbfputflt(depth, file_out);
+        }
+
        if (global_opts.debug_level >= 1) {
                /* print lat/lon/alt on one easily greppable line */
                printf(MYNAME " waypt_disp: Lat = %d   Lon = %d   Alt = %d\n",Lat, Lon, alt);
@@ -954,7 +968,7 @@ data_write(void)
 {
        short int NumWaypoints, MajorVersion, MinorVersion, NumRoutes, NumTrails, NumIcons;
        setshort_length(mkshort_handle, 15);
-       MajorVersion = 2;
+       MajorVersion = writing_version;
        MinorVersion = 0;
 
        NumWaypoints = waypt_count();
diff --git a/reference/lowrance-v2-unicsv.txt b/reference/lowrance-v2-unicsv.txt
new file mode 100644 (file)
index 0000000..dc10dd4
--- /dev/null
@@ -0,0 +1,70 @@
+No,Latitude,Longitude,Name,Altitude,Symbol,Date,Time\r
+1,42.370556,-82.670001,"Belle River Ridge",0.0,"diamond 1",2005/08/16,21:45:09\r
+2,42.399444,-82.819443,"Dumping Ground",0.0,"diamond 1",2005/08/16,21:49:10\r
+3,42.545553,-82.849665,"001",174.0,"diamond 1",2006/06/17,08:18:18\r
+4,42.382322,-82.900455,"002",176.2,"diamond 1",2006/06/17,11:17:54\r
+5,42.382602,-82.899401,"003",174.7,"diamond 1",2006/06/17,11:33:24\r
+6,42.367986,-82.913777,"004",174.3,"diamond 1",2006/06/17,13:10:14\r
+7,42.368006,-82.914354,"005",177.1,"diamond 1",2006/06/17,13:34:57\r
+8,42.368785,-82.914282,"006",174.3,"diamond 1",2006/06/17,14:27:45\r
+9,42.369304,-82.914020,"007",174.3,"diamond 1",2006/06/17,14:37:20\r
+10,42.369597,-82.913930,"008",173.1,"diamond 1",2006/06/17,14:41:56\r
+11,42.481937,-82.822409,"S",0.0,"diamond 1",2006/06/17,10:06:26\r
+12,42.377215,-82.899266,"Dlphn Dprk",0.0,"diamond 1",2003/07/04,07:31:09\r
+13,42.379818,-82.897102,"Delphine10",0.0,"diamond 1",2003/07/04,07:31:09\r
+14,42.382801,-82.895633,"Church Mrn",0.0,"diamond 1",2003/07/04,07:31:09\r
+15,42.373586,-82.890135,"Del 3Can R",0.0,"diamond 1",2003/07/04,07:31:09\r
+16,42.388334,-82.892749,"Trgh Rkpil",0.0,"diamond 1",2003/07/04,07:31:09\r
+17,42.389785,-82.890189,"Cn Grspt Shl",0.0,"diamond 1",2003/07/04,07:31:09\r
+18,42.409354,-82.880184,"Gpt Frm Wd",0.0,"diamond 1",2003/07/04,07:31:09\r
+19,42.398392,-82.884141,"Aba1Old",0.0,"fish",2000/01/31,19:24:00\r
+20,42.399171,-82.882140,"Aba4",0.0,"fish",2000/01/31,19:28:15\r
+21,42.436487,-82.869918,"Gpyc Wdbed",0.0,"diamond 1",2003/07/04,07:31:09\r
+22,42.447448,-82.866466,"Lman 5Rock",0.0,"diamond 1",2003/07/04,07:31:09\r
+23,42.448087,-82.866935,"Lman 5R N",0.0,"diamond 1",2003/07/04,07:31:09\r
+24,42.450654,-82.861968,"Mansion 12",0.0,"diamond 1",2003/07/04,07:31:09\r
+25,42.469020,-82.860652,"9Ml Rk Pil",0.0,"diamond 1",2003/07/04,07:31:09\r
+26,42.471334,-82.860634,"9Ml Spintp",0.0,"diamond 1",2003/07/04,07:31:09\r
+27,42.498168,-82.876471,"Bwal Beds1",0.0,"diamond 1",2003/07/04,07:31:09\r
+28,42.499251,-82.869107,"11Mi Wh Rk",0.0,"diamond 1",2003/07/04,07:31:09\r
+29,42.494320,-82.861968,"Bsw 14 1",0.0,"diamond 1",2003/07/04,07:31:09\r
+30,42.495669,-82.828772,"Bluswl Way13",0.0,"diamond 1",2003/07/04,07:31:09\r
+31,42.493881,-82.854604,"Lmarker",0.0,"diamond 1",2003/07/04,07:31:09\r
+32,42.503232,-82.801588,"Cn Memprk Rk",0.0,"airplane",2003/08/03,06:00:17\r
+33,42.502966,-82.801570,"Cn Memprk R2",0.0,"airplane",2003/08/03,06:01:26\r
+34,42.510667,-82.880437,"12Mile Cn",0.0,"diamond 1",2003/07/04,07:31:09\r
+35,42.521084,-82.869621,"Wht Pav 8F",0.0,"diamond 1",2003/07/04,07:31:09\r
+36,42.523097,-82.831647,"Crmr9Plt1",0.0,"tree stand",2006/08/24,13:22:43\r
+37,42.521815,-82.830313,"Cfmr9Plt2",0.0,"tree stand",2006/08/24,13:23:42\r
+38,42.531686,-82.798848,"700 4  Hump",0.0,"x 3",2003/07/04,07:31:09\r
+39,42.554636,-82.782732,"Pthurn Cn1",0.0,"diamond 1",2003/07/04,07:31:09\r
+40,42.572335,-82.773538,"Cn Clnt Flat",0.0,"diamond 1",2003/07/04,07:31:09\r
+41,42.571186,-82.753132,"Bet-Crbc Wrk",0.0,"wreck",2006/06/14,14:26:02\r
+42,42.622747,-82.766048,"Jefs Bigrk",0.0,"x 3",2003/07/04,07:31:09\r
+43,42.552027,-82.728507,"011",0.0,"two fish",2006/08/12,08:59:52\r
+44,42.552253,-82.728976,"012",0.0,"two fish",2006/08/12,09:20:00\r
+45,42.551250,-82.727615,"Mch Outbrk",0.0,"diamond 1",2003/07/04,07:31:09\r
+46,42.551549,-82.727948,"Mg Midchrck",0.0,"diamond 1",2003/07/04,07:31:09\r
+47,42.531354,-82.706668,"Old Ch Gap",0.0,"diamond 1",2003/07/04,07:31:09\r
+48,42.536269,-82.683855,"Oldsth Wd7",0.0,"diamond 1",2003/07/04,07:31:09\r
+49,42.508900,-82.713851,"12Rk Clsrhmp",0.0,"diamond 1",2003/07/04,07:31:09\r
+50,42.509026,-82.714194,"12Rk Sml",0.0,"diamond 1",2003/07/04,07:31:09\r
+51,42.509252,-82.715005,"12Rk Closhmp",0.0,"diamond 1",2003/07/04,07:31:09\r
+52,42.510195,-82.714023,"12Rk Bigi",0.0,"diamond 1",2003/07/04,07:31:09\r
+53,42.411064,-82.880184,"Wpt 042*",0.0,"fish",2008/06/19,14:18:50\r
+54,42.411982,-82.878346,"Wpt 043*",0.0,"fish",2008/06/19,14:19:27\r
+55,42.509218,-82.715420,"Wpt 044*",0.0,"fish",2008/06/19,14:20:05\r
+56,42.360813,-82.926756,"009",173.7,"diamond 1",2008/06/20,07:40:55\r
+57,42.361220,-82.926207,"010",174.7,"diamond 1",2008/06/20,07:53:04\r
+58,42.387395,-82.895246,"013",174.7,"diamond 1",2008/06/20,12:03:42\r
+59,42.388913,-82.894047,"014",174.0,"diamond 1",2008/06/20,12:16:39\r
+60,42.409493,-82.881329,"015",176.5,"diamond 1",2008/06/20,12:51:04\r
+61,42.410478,-82.881374,"016",176.8,"diamond 1",2008/06/20,13:06:07\r
+62,42.411104,-82.880527,"017",-3048.0,"diamond 1",2008/06/20,13:16:10\r
+63,42.382415,-82.900131,"018",172.2,"diamond 1",2008/06/21,10:10:10\r
+64,42.380771,-82.899347,"019",-3048.0,"diamond 1",2008/06/21,10:57:22\r
+65,42.413326,-82.879121,"020",-3048.0,"diamond 1",2008/06/21,13:03:09\r
+66,42.378553,-82.900104,"021",173.1,"diamond 1",2008/06/21,14:38:08\r
+67,42.950009,-85.607586,"012",-3048.0,"diamond 1",2008/06/28,14:01:28\r
+68,41.413022,-85.724372,"Icon 1",0.0,"diamond 1",,\r
+69,41.413035,-85.724399,"Icon 2",0.0,"diamond 1",,\r
diff --git a/reference/lowrance-v2.usr b/reference/lowrance-v2.usr
new file mode 100644 (file)
index 0000000..91402b9
Binary files /dev/null and b/reference/lowrance-v2.usr differ
diff --git a/reference/lowrance-v3-unicsv.txt b/reference/lowrance-v3-unicsv.txt
new file mode 100644 (file)
index 0000000..f47837e
--- /dev/null
@@ -0,0 +1,70 @@
+No,Latitude,Longitude,Name,Altitude,Symbol,Depth,Date,Time\r
+1,42.370556,-82.670001,"Belle River Ridge",0.0,"diamond 1",,2005/08/16,21:45:09\r
+2,42.399444,-82.819443,"Dumping Ground",0.0,"diamond 1",,2005/08/16,21:49:10\r
+3,42.545553,-82.849665,"001",174.0,"diamond 1",,2006/06/17,08:18:18\r
+4,42.382322,-82.900455,"002",176.2,"diamond 1",,2006/06/17,11:17:54\r
+5,42.382602,-82.899401,"003",174.7,"diamond 1",,2006/06/17,11:33:24\r
+6,42.367986,-82.913777,"004",174.3,"diamond 1",,2006/06/17,13:10:14\r
+7,42.368006,-82.914354,"005",177.1,"diamond 1",,2006/06/17,13:34:57\r
+8,42.368785,-82.914282,"006",174.3,"diamond 1",,2006/06/17,14:27:45\r
+9,42.369304,-82.914020,"007",174.3,"diamond 1",,2006/06/17,14:37:20\r
+10,42.369597,-82.913930,"008",173.1,"diamond 1",,2006/06/17,14:41:56\r
+11,42.481937,-82.822409,"S",0.0,"diamond 1",,2006/06/17,10:06:26\r
+12,42.377215,-82.899266,"Dlphn Dprk",0.0,"diamond 1",,2003/07/04,07:31:09\r
+13,42.379818,-82.897102,"Delphine10",0.0,"diamond 1",,2003/07/04,07:31:09\r
+14,42.382801,-82.895633,"Church Mrn",0.0,"diamond 1",,2003/07/04,07:31:09\r
+15,42.373586,-82.890135,"Del 3Can R",0.0,"diamond 1",,2003/07/04,07:31:09\r
+16,42.388334,-82.892749,"Trgh Rkpil",0.0,"diamond 1",,2003/07/04,07:31:09\r
+17,42.389785,-82.890189,"Cn Grspt Shl",0.0,"diamond 1",,2003/07/04,07:31:09\r
+18,42.409354,-82.880184,"Gpt Frm Wd",0.0,"diamond 1",,2003/07/04,07:31:09\r
+19,42.398392,-82.884141,"Aba1Old",0.0,"fish",,2000/01/31,19:24:00\r
+20,42.399171,-82.882140,"Aba4",0.0,"fish",,2000/01/31,19:28:15\r
+21,42.436487,-82.869918,"Gpyc Wdbed",0.0,"diamond 1",,2003/07/04,07:31:09\r
+22,42.447448,-82.866466,"Lman 5Rock",0.0,"diamond 1",,2003/07/04,07:31:09\r
+23,42.448087,-82.866935,"Lman 5R N",0.0,"diamond 1",,2003/07/04,07:31:09\r
+24,42.450654,-82.861968,"Mansion 12",0.0,"diamond 1",,2003/07/04,07:31:09\r
+25,42.469020,-82.860652,"9Ml Rk Pil",0.0,"diamond 1",,2003/07/04,07:31:09\r
+26,42.471334,-82.860634,"9Ml Spintp",0.0,"diamond 1",,2003/07/04,07:31:09\r
+27,42.498168,-82.876471,"Bwal Beds1",0.0,"diamond 1",,2003/07/04,07:31:09\r
+28,42.499251,-82.869107,"11Mi Wh Rk",0.0,"diamond 1",,2003/07/04,07:31:09\r
+29,42.494320,-82.861968,"Bsw 14 1",0.0,"diamond 1",,2003/07/04,07:31:09\r
+30,42.495669,-82.828772,"Bluswl Way13",0.0,"diamond 1",,2003/07/04,07:31:09\r
+31,42.493881,-82.854604,"Lmarker",0.0,"diamond 1",,2003/07/04,07:31:09\r
+32,42.503232,-82.801588,"Cn Memprk Rk",0.0,"airplane",,2003/08/03,06:00:17\r
+33,42.502966,-82.801570,"Cn Memprk R2",0.0,"airplane",,2003/08/03,06:01:26\r
+34,42.510667,-82.880437,"12Mile Cn",0.0,"diamond 1",,2003/07/04,07:31:09\r
+35,42.521084,-82.869621,"Wht Pav 8F",0.0,"diamond 1",,2003/07/04,07:31:09\r
+36,42.523097,-82.831647,"Crmr9Plt1",0.0,"tree stand",,2006/08/24,13:22:43\r
+37,42.521815,-82.830313,"Cfmr9Plt2",0.0,"tree stand",,2006/08/24,13:23:42\r
+38,42.531686,-82.798848,"700 4  Hump",0.0,"x 3",,2003/07/04,07:31:09\r
+39,42.554636,-82.782732,"Pthurn Cn1",0.0,"diamond 1",,2003/07/04,07:31:09\r
+40,42.572335,-82.773538,"Cn Clnt Flat",0.0,"diamond 1",,2003/07/04,07:31:09\r
+41,42.571186,-82.753132,"Bet-Crbc Wrk",0.0,"wreck",,2006/06/14,14:26:02\r
+42,42.622747,-82.766048,"Jefs Bigrk",0.0,"x 3",,2003/07/04,07:31:09\r
+43,42.552027,-82.728507,"011",0.0,"two fish",,2006/08/12,08:59:52\r
+44,42.552253,-82.728976,"012",0.0,"two fish",,2006/08/12,09:20:00\r
+45,42.551250,-82.727615,"Mch Outbrk",0.0,"diamond 1",,2003/07/04,07:31:09\r
+46,42.551549,-82.727948,"Mg Midchrck",0.0,"diamond 1",,2003/07/04,07:31:09\r
+47,42.531354,-82.706668,"Old Ch Gap",0.0,"diamond 1",,2003/07/04,07:31:09\r
+48,42.536269,-82.683855,"Oldsth Wd7",0.0,"diamond 1",,2003/07/04,07:31:09\r
+49,42.508900,-82.713851,"12Rk Clsrhmp",0.0,"diamond 1",,2003/07/04,07:31:09\r
+50,42.509026,-82.714194,"12Rk Sml",0.0,"diamond 1",,2003/07/04,07:31:09\r
+51,42.509252,-82.715005,"12Rk Closhmp",0.0,"diamond 1",,2003/07/04,07:31:09\r
+52,42.510195,-82.714023,"12Rk Bigi",0.0,"diamond 1",,2003/07/04,07:31:09\r
+53,42.411064,-82.880184,"Wpt 042*",0.0,"fish",,2008/06/19,14:18:50\r
+54,42.411982,-82.878346,"Wpt 043*",0.0,"fish",,2008/06/19,14:19:27\r
+55,42.509218,-82.715420,"Wpt 044*",0.0,"fish",,2008/06/19,14:20:05\r
+56,42.360813,-82.926756,"009",173.7,"diamond 1",1.0,2008/06/20,07:40:55\r
+57,42.361220,-82.926207,"010",174.7,"diamond 1",1.1,2008/06/20,07:53:04\r
+58,42.387395,-82.895246,"013",174.7,"diamond 1",0.9,2008/06/20,12:03:42\r
+59,42.388913,-82.894047,"014",174.0,"diamond 1",1.2,2008/06/20,12:16:39\r
+60,42.409493,-82.881329,"015",176.5,"diamond 1",1.8,2008/06/20,12:51:04\r
+61,42.410478,-82.881374,"016",176.8,"diamond 1",1.4,2008/06/20,13:06:07\r
+62,42.411104,-82.880527,"017",-3048.0,"diamond 1",,2008/06/20,13:16:10\r
+63,42.382415,-82.900131,"018",172.2,"diamond 1",1.0,2008/06/21,10:10:10\r
+64,42.380771,-82.899347,"019",-3048.0,"diamond 1",,2008/06/21,10:57:22\r
+65,42.413326,-82.879121,"020",-3048.0,"diamond 1",,2008/06/21,13:03:09\r
+66,42.378553,-82.900104,"021",173.1,"diamond 1",2.2,2008/06/21,14:38:08\r
+67,42.950009,-85.607586,"012",-3048.0,"diamond 1",,2008/06/28,14:01:28\r
+68,41.413022,-85.724372,"Icon 1",0.0,"diamond 1",,,\r
+69,41.413035,-85.724399,"Icon 2",0.0,"diamond 1",,,\r
diff --git a/reference/lowrance-v3.usr b/reference/lowrance-v3.usr
new file mode 100644 (file)
index 0000000..abd445f
Binary files /dev/null and b/reference/lowrance-v3.usr differ